import React, { Component } from 'react';
import { withRouter, Route } from 'react-router-dom'
import types from 'prop-types'

@withRouter
class Mylink extends Component {
  render() {
    let { tag, active, to } = this.props
    let Tag = tag
    return (
      <Route path={to} children={({ match }) => {
        return (
          <Tag
            onClick={() => this.props.history.push(to)}
            className={match ? active : ''}
          >
            {this.props.children || '导航'}
          </Tag>
        )
      }} />
    )
  }
}

// props类型限制
Mylink.propTypes = {
  to: types.string.isRequired,
  tag: types.string,
  active: types.string
}

// props默认值
Mylink.defaultProps = {
  tag: 'a',
  active: 'active'
}




export default Mylink;
